package com.google.project.server.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.project.shared.ProjectReportDTO;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class ProjectReport implements Serializable{
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;
	@Persistent
	private Long createdOnDate;
	@Persistent
	private String fromUserID;
	@Persistent
	private String fromUserName;
	@Persistent
	private int status;
	@Persistent
	private String projectId;
	@Persistent
	private Project project;
	
	
	
	public ProjectReport() {
	}
	
	public ProjectReport(String id, Long createdOnDate, String fromUserID,
			String fromUserName, int status, String projectId) {
		super();
		this.id = id;
		this.createdOnDate = createdOnDate;
		this.fromUserID = fromUserID;
		this.fromUserName = fromUserName;
		this.status = status;
		this.projectId = projectId;
	}
	public ProjectReport(ProjectReportDTO projectReportDTO) {
		this.id = projectReportDTO.getId();
		this.createdOnDate = projectReportDTO.getCreatedOnDate();
		this.fromUserID = projectReportDTO.getFromUserID();
		this.fromUserName = projectReportDTO.getFromUserName();
		this.status = projectReportDTO.getStatus();
		this.projectId = projectReportDTO.getProjectId();
	}

	public ProjectReportDTO toDTO() {
		ProjectReportDTO data = new ProjectReportDTO();
		data.setId(id);
		data.setCreatedOnDate(createdOnDate);
		data.setFromUserID(fromUserID);
		data.setFromUserName(fromUserName);
		data.setStatus(status);
		data.setProjectId(projectId);
		data.setProjectDTO(this.project.toDTO());
		return data;
	}
	public void updateFromDTO(ProjectReportDTO projectReportDTO) {
		this.createdOnDate = projectReportDTO.getCreatedOnDate();
		this.fromUserID = projectReportDTO.getFromUserID();
		this.fromUserName = projectReportDTO.getFromUserName();
		this.status = projectReportDTO.getStatus();
		this.projectId = projectReportDTO.getProjectId();
	}
	
	@Persistent(mappedBy = "projectReport")
	@Element(dependent = "true")
	private List<ProjectReportDetail> listOfReportDetail = new ArrayList<ProjectReportDetail>();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Long getCreatedOnDate() {
		return createdOnDate;
	}

	public void setCreatedOnDate(Long createdOnDate) {
		this.createdOnDate = createdOnDate;
	}

	public String getFromUserID() {
		return fromUserID;
	}

	public void setFromUserID(String fromUserID) {
		this.fromUserID = fromUserID;
	}

	public String getFromUserName() {
		return fromUserName;
	}

	public void setFromUserName(String fromUserName) {
		this.fromUserName = fromUserName;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public List<ProjectReportDetail> getListOfReportDetail() {
		return listOfReportDetail;
	}

	public void setListOfReportDetail(List<ProjectReportDetail> listOfReportDetail) {
		this.listOfReportDetail = listOfReportDetail;
	}
	
}
